package com.kiln.juxingqs.ui.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import client.global.commlib.network.data.JsonResult
import com.kiln.juxingqs.api.bean.Zcjl
import com.kiln.juxingqs.ui.viewmodel.MiddleVm


class AvailableAssetsViewModel(app: Application) : MiddleVm(app) {
    val isShowing = MutableLiveData<Boolean>(false)

    val isOneLoading = MutableLiveData<Boolean>(false)
    val isTwoLoading = MutableLiveData<Boolean>(false)
    val isThreeLoading = MutableLiveData<Boolean>(false)
    val isFourLoading = MutableLiveData<Boolean>(false)
    val isFiveLoading = MutableLiveData<Boolean>(false)
    val isSixLoading = MutableLiveData<Boolean>(false)
    val pageOne = MutableLiveData<Int>(0)
    val pageTwo = MutableLiveData<Int>(0)
    val pageThree = MutableLiveData<Int>(0)
    val pageFour = MutableLiveData<Int>(0)
    val pageFive = MutableLiveData<Int>(0)
    val pageSix = MutableLiveData<Int>(0)
    val callOne = MutableLiveData<JsonResult<Zcjl>>()
    val callTwo = MutableLiveData<JsonResult<Zcjl>>()
    val callThree = MutableLiveData<JsonResult<Zcjl>>()
    val callFour = MutableLiveData<JsonResult<Zcjl>>()
    val callFive = MutableLiveData<JsonResult<Zcjl>>()
    val callSix = MutableLiveData<JsonResult<Zcjl>>()
    val switchValue = MutableLiveData<Int>(-1)

    val startDate = MutableLiveData<String>("2018-01-01")
    val endDate = MutableLiveData<String>("截止时间")

    fun holdOne() {
        if (isOneLoading.value!!)
            return
        hold({
            server.zcjl(pageOne.value!!, 0, startDate.value!!, endDate.value!!)
        }, {
            isOneLoading.value = true
            pageOne.value = pageOne.value!! + 1
        }, {
            callOne.value = it
        }, complete = {
            isOneLoading.value = false
        })
    }

    fun holdTwo() {
        if (isTwoLoading.value!!)
            return
        hold({
            server.zcjl(pageTwo.value!!, 2, startDate.value!!, endDate.value!!)
        }, {
            isTwoLoading.value = true
            pageTwo.value = pageTwo.value!! + 1
        }, {
            callTwo.value = it
        }, complete = {
            isTwoLoading.value = false
        })
    }

    fun holdThree() {
        if (isThreeLoading.value!!)
            return
        hold({
            server.zcjl(pageThree.value!!, 6, startDate.value!!, endDate.value!!)
        }, {
            isThreeLoading.value = true
            pageThree.value = pageThree.value!! + 1
        }, {
            callThree.value = it
        }, complete = {
            isThreeLoading.value = false
        })
    }

    fun holdFour() {
        if (isFourLoading.value!!)
            return
        hold({
            server.zcjl(pageFour.value!!, 7, startDate.value!!, endDate.value!!)
        }, {
            isFourLoading.value = true
            pageFour.value = pageFour.value!! + 1
        }, {
            callFour.value = it
        }, complete = {
            isFourLoading.value = false
        })
    }

    fun holdFive() {
        if (isFiveLoading.value!!)
            return
        hold({
            server.zcjl(pageFive.value!!, 1, startDate.value!!, endDate.value!!)
        }, {
            isFiveLoading.value = true
            pageFive.value = pageFive.value!! + 1
        }, {
            callFive.value = it
        }, complete = {
            isFiveLoading.value = false
        })
    }

    fun holdSix() {
        if (isSixLoading.value!!)
            return
        hold({
            server.zcjl(pageSix.value!!, 3, startDate.value!!, endDate.value!!)
        }, {
            isSixLoading.value = true
            pageSix.value = pageSix.value!! + 1
        }, {
            callSix.value = it
        }, complete = {
            isSixLoading.value = false
        })
    }
}